window.document.addEventListener("saveData", function (evt) {
try {
var location = evt.target.location.toString().slice(0, 38);
if (location != 'http://appwared.com/budaneki/settings/') {
alert('can\'t save, location wrong:' + location);
return false;
}
/*transfer datato page*/
whatTheHell.saveDataFromPage();
} catch(err) {
alert(err);
};
},
false, true);
/*test the database and create one if there is a problem*/
var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
file.append("budaneki.sqlite");
var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);
var mdbConn = storageService.openDatabase(file); // Will also create the file if it does not exist
var tableExists = mdbConn.tableExists("budanekiLinkDb");
if (tableExists == false) {
var start = new Array();
whatTheHell.resetDb(false);
} else {
try {
var statement = mdbConn.createStatement("SELECT * FROM budanekiLinkDb");
statement.executeStep();
var rid = statement.row.id;
} catch(err) {
var start = new Array();
whatTheHell.resetDb(false);
}
}
/*load the linkList*/
whatTheHell.generateLinkList();
/*open new tab on first run*/
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
try {
var lastVer = prefs.getCharPref("budaneki.lastVersion");
//function for generating the link list [from the database for an example]
this.generateLinkList = function () {
/*SQLite ile bombastik*/
try {
whatTheHell.urlList = new Array();
var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
file.append("budaneki.sqlite");
var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);
var mdbConn = storageService.openDatabase(file); // Will also create the file if it does not exist
var statement = mdbConn.createStatement("SELECT * FROM budanekiLinkDb");
try {
while (statement.executeStep()) {
var urlId = statement.row.id;
var urlName = statement.row.name;
var urlThe = statement.row.url;
var urlEscape = statement.row.escape_url;
var urlSize = statement.row.size;
var urlType = statement.row.type;
whatTheHell.urlList.push({
'id': urlId,
'name': urlName,
'url': urlThe,
'escape_url': urlEscape,
'size': urlSize,
'type': urlType
});
}
}
finally {
statement.reset();
}
} catch(err) {
alert(err);
}
return true;
}
this.resetDb = function (urlList) {
try {
if (urlList == false) {
/*list of the default providers*/
var urlList = new Array({
'name': 'sesli s├╢zl├╝k',
'url': 'http://m.seslisozluk.com/?word=',
'escape_url': 0,
'size': 0,
'type': 0
},
{
'name': 'ekşi sözlük',
'url': 'http://sozluk.sourtimes.org/show.asp?t=',
'escape_url': 0,
'size': 0,
'type': 0
},
{
'name': 'Google',
'url': 'http://www.google.com/search?q=',
'escape_url': 0,
'size': 0,
'type': 0
},
{
'name': 'Google images',
'url': 'http://images.google.com/images?q=',
'escape_url': 0,
'size': 0,
'type': 0
});
}
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
file.append("budaneki.sqlite");
var storageService = Components.classes["@mozilla.org/storage/service;1"]